﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using LitJson;
using SurrealTodoAdapter;
namespace TestConsole
{
    class Program
    {
        public static SurrealTodoService Service;

        static void Main(string[] args)
        {
            Service = new SurrealTodoService("http://qugaoding.com.cat211.redphp.cn/ajax.php");
            

            //Service.ClearUser();
            //Service.AddNewTask(testUserName,"编码真纠结"+DateTime.Now.Second+DateTime.Now.DayOfWeek);



            Console.WriteLine(DateTime.Now.AddDays(-(int)DateTime.Now.DayOfWeek+1));
            Console.ReadKey();

                
        }


        private static  void GetList()
        {
            string testUserName = "去搞定";
            var tasks = Service.GetToDoTasks(testUserName);

            tasks.ForEach(t =>
            {
                string content = Encoding.GetEncoding("gb2312").GetString(Encoding.UTF8.GetBytes(t.text));
                Console.WriteLine(t.text);
            });

            Console.ReadKey();
        }

        private static void AddTestData(string testUserName)
        {
            Service.AddNewTask(testUserName, "Fins", DateTime.Now.AddDays(1));
            Service.AddNewTask(testUserName, "Finisheds", DateTime.Now);
            Service.AddNewTask(testUserName, "Love lus", DateTime.Now);

            //可以查看
            //http://qugaoding.com.cat211.redphp.cn
            //用户有两个list--- ToDo 和Finished
            //将ToDo的task转移到Finished中
            Service.FinishAllCurrentTasks(testUserName);
            CheckTaskList(testUserName);

            Service.AddNewTask(testUserName, "Fins", DateTime.Now.AddDays(1));
            Service.AddNewTask(testUserName, "Finisheds", DateTime.Now);
            Service.AddNewTask(testUserName, "Love lus", DateTime.Now);

            CheckTaskList(testUserName);

            foreach (var timingTask in Service.GetTimings())
            {
                Console.WriteLine(timingTask.timing + timingTask.text);
            }
        }

        private static void CheckTaskList(string userName)
        {
            var taskList = Service.GetToDoTasks(userName);
            Console.WriteLine(taskList.Count);
            foreach (var task in taskList)
            {
                Console.WriteLine(task.text);
            }
        }
    }
}
    